<div style="padding: 20px;" class="layui-form  seller-alone-form">

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i> 消息名称：</label>
        <div class="layui-input-inline seller-inline-4">
            <input type="text" name="name" value="{$data.name}" required lay-verify="required" placeholder="请输入消息名称(关键字)" autocomplete="off" class="layui-input">
            <input type="hidden" name="id" value="{$data.id}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">关注回复：</label>
        <div class="layui-input-inline seller-inline-4">
            <input type="checkbox" value="1" {if condition="$data.is_attention eq '1' "}checked = "" {/if} name="is_attention" lay-skin="switch" lay-filter="switchTest" title="开关"><div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em></em><i></i></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">默认回复：</label>
        <div class="layui-input-inline seller-inline-4">
            <input type="checkbox" value="1" name="is_default" {if condition="$data.is_default eq '1' "}checked = "" {/if} lay-skin="switch" lay-filter="switchTest" title="开关"><div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em></em><i></i></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">禁用：</label>
        <div class="layui-input-inline seller-inline-4">
            <input type="checkbox" value="2" name="enable" {if condition="$data.enable eq '2' "}checked = "" {/if}  lay-skin="switch" lay-filter="switchTest" title="开关"><div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em></em><i></i></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i> 消息类型：</label>
        <div class="layui-input-inline seller-inline-4">
            <select name="type" lay-filter="message-type">
                <option value="1" {if condition="$data.type eq '1' "}selected = "" {/if} >文字消息</option>
                <option value="3" {if condition="$data.type eq '3' "}selected = "" {/if} >图文消息</option>
            </select>
        </div>
    </div>

    <div class="message-type keyword"  {if condition="$data.type neq '1' "} style="display: none;" {/if}>
        <div class="layui-form-item">
            <label class="layui-form-label">消息内容：</label>
            <div class="layui-input-inline seller-inline-4">
                <textarea class="layui-textarea" name="params[content]">{$data.params.content}</textarea>
            </div>
        </div>
    </div>

    <div class="layui-form-item" {if condition="$data.type neq '3' "} style="display: none;" {/if}>
        <label class="layui-form-label">提醒：</label>
    
        <div class="layui-input-block" style="font-size:14px; padding-top:10px;">
            <p>请稍后进入图文编辑页面继续编辑，否则图文消息不生效。</p>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">注意：</label>
    
        <div class="layui-input-block" style="font-size:14px; padding-top:10px;">
            <p>消息名称请勿填写“客服”，当用户输入“客服”时，将消息自动转发至客服系统。</p>
        </div>
    </div> 
 
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="open_spec" value="0">
            {:zlserverToken()}
            <button id="message_edit_save" class="layui-btn" lay-submit="" lay-filter="save">保存</button>
        </div>
    </div>
    {:zlserverToken()}
</div>

<script src="../layui/layui.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form;
        form.render();
  
        //保存用户
        form.on('submit(save)', function(data){
            $("#message_edit_save").addClass("layui-btn-disabled");
            $('#message_edit_save').attr("disabled", true);

            $.ajax({
                type: 'post',
                url: '{:url("Wechat/editMessage")}',
                data: data.field,
                dataType: 'json',
                success: function (e) { 
                    if(e.status === true){ 
                        layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,id: 'layerDemoAuto'
                            ,content: '<div style="padding: 20px 100px;">'+ e.msg +'</div>'
                            ,btn: '关闭'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0.3 //显示遮罩
                            ,yes: function(){
                                parent.layui.admin.events.changeTabAndRefresh('/manage/wechat/index.html');
                            },close: function() {
                                console.log('close');
                            },end: function () {
                                parent.layui.admin.events.changeTabAndRefresh('/manage/wechat/index.html');
                            }
                        });
                    }else{
                        $("#message_edit_save").removeClass("layui-btn-disabled");
                        $('#message_edit_save').removeAttr("disabled");

                        layer.msg(e.msg, {time: 1300});
                    }
                }
            });
            return false;
        });
    });
</script>